<template>
  <div class="comment-box">
    <h3>发表评论</h3>
    <hr>
    <textarea placeholder="请输入要BB的内容(最多吐槽120字)" maxlength="120"></textarea>
    <mt-button type="primary" size="large">发表评论</mt-button>
    <div class="list">
      <div class="item" v-for="(item,i) in contentList" :key="i">
        <div class="index-name">第 {{ i+1 }} 楼:{{ item.user_name}} 发表时间：{{ item.add_time | dateFormat}}</div>
        <div class="item-content">{{ item.content != 'undefined' ? item.content : '你没有评论' }}</div>
      </div>
    </div>
    <mt-button type="danger" size="large" plain @click="addMore">加载更多</mt-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      contentList: [],
      pageindex: 1
    };
  },
  props: ["id"],
  created() {
    this.getContentList();
  },
  methods: {
    getContentList() {
      this.$http
        .get("api/getcomments/" + this.id + "?pageindex=" + this.pageindex)
        .then(res => {
          if (res.body.status === 0) {
            this.contentList = this.contentList.concat(res.body.message);
          } else {
            Toast("获取评论失败");
          }
        });
    },
    addMore() {
      this.pageindex++;
      this.getContentList();
    }
  }
};
</script>

<style lang="scss" scoped>
.comment-box {
  h3 {
    text-align: left;
    font-size: 14px;
    color: #000;
  }
  textarea {
    font-size: 12px;
    margin: 0;
    height: 85px;
  }
  .list {
    margin: 5px 0;
    .item {
      font-size: 13px;
      .index-name {
        line-height: 30px;
        background-color: #ccc;
        .item-content {
          line-height: 35px;
          text-indent: 2em;
        }
      }
    }
  }
}
</style>
